package com.bioscript.standalone.dataStructures;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public final class Gene 
{
	private Range actualRange , expectedRange;
	
	public Gene(Range actualRange)
	{
		this.actualRange = new Range(actualRange.getLowerLimit(), 
				actualRange.getUpperLimit(), actualRange.getName()).setMetadata(actualRange.getMetadata());
	}
	
	public Range getGene()
	{
		return new Range(actualRange.getLowerLimit(),
				actualRange.getUpperLimit(),
				actualRange.getName()).setMetadata(actualRange.getMetadata());
	}
	
	public Range getExpectedPosition()
	{
		return new Range(expectedRange.getLowerLimit(),
				expectedRange.getUpperLimit(),
				expectedRange.getName()).setMetadata(expectedRange.getMetadata());
	}
	
	public Gene setExpectedPosition(Range expectedRange)
	{
		this.expectedRange = new Range(expectedRange.getLength(), 
				expectedRange.getUpperLimit(),
				expectedRange.getName()).setMetadata(expectedRange.getMetadata());
		return this;
	}
	
	public Gene setMetaData(String metadata)
	{
		actualRange.setMetadata(metadata);
		return this;
	}
	
	public Element toXML(Document doc) {
		Element gene = doc.createElement("gene");
		gene.setAttribute("name", actualRange.getName());
		gene.setAttribute("start", String.valueOf(actualRange.getLowerLimit()));
		gene.setAttribute("end", String.valueOf(actualRange.getUpperLimit()));
		if (expectedRange != null)
		{
			gene.setAttribute("refStart", String.valueOf(expectedRange.getLowerLimit()));
			gene.setAttribute("refEnd", String.valueOf(expectedRange.getUpperLimit()));
		}
		gene.setAttribute("metadata", actualRange.getMetadata() == null ? "" : actualRange.getMetadata());
		return gene;
	}
} // Gene
